function(my_check_glib_type_align_and_define_macro type_name macro_name)
    find_package(PkgConfig REQUIRED)
    pkg_check_modules(GLIB REQUIRED glib-2.0)

    set(CHECK_TYPE_ALIGN_CODE "
#include <stdio.h>
#include <glib.h>

int main() {
    printf(\"%zu\\n\", G_ALIGNOF(${type_name}));
    return 0;
}
")

    set(temp_source "${CMAKE_CURRENT_BINARY_DIR}/check_${type_name}_align.c")
    file(WRITE ${temp_source} "${CHECK_TYPE_ALIGN_CODE}")

    # 手动添加编译和运行逻辑
    set(output_binary "${CMAKE_CURRENT_BINARY_DIR}/check_${type_name}_align")
    add_custom_command(
        OUTPUT ${output_binary}
        COMMAND ${CMAKE_C_COMPILER} ${temp_source} -o ${output_binary}
        -I${GLIB_INCLUDE_DIRS} ${GLIB_LDFLAGS} ${GLIB_LIBRARIES}
        COMMENT "Compiling alignment test for ${type_name}"
    )
    execute_process(
        COMMAND ${output_binary}
        RESULT_VARIABLE result
        OUTPUT_VARIABLE output
        ERROR_VARIABLE error_output
    )

    # 如果测试失败，则将宏定义为0
    if(result EQUAL 0)
        string(STRIP "${output}" output)
        message(STATUS "Alignment of ${type_name}: ${output}")
        set(${macro_name} ${output} PARENT_SCOPE)
        add_definitions(-D${macro_name}=${output})
    else()
        message(STATUS "Failed to determine alignment of ${type_name}, setting ${macro_name} to 0")
        set(${macro_name} 0 PARENT_SCOPE)
        add_definitions(-D${macro_name}=0)
    endif()
endfunction()

# 调用函数检查多个类型的对齐方式
#my_check_glib_type_align_and_define_macro(guint32 ALIGNOF_GUINT32)
#my_check_glib_type_align_and_define_macro(gpointer ALIGNOF_GPOINTER)
#my_check_glib_type_align_and_define_macro(gchar ALIGNOF_GCHAR)
